/*
 * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef SLE_CONCIFG_MANAGER_H
#define SLE_CONCIFG_MANAGER_H
#include "sle_device_config.h"
#include "sle_hilog.h"
#include "sle_device_config.h"
#include "sle_error_code.h"
#include <stdio.h>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <map>

namespace OHOS {
namespace NearLink {
namespace SleStandard {

#ifndef SLE_FILE_DEFAULT_PATH
#define SLE_FILE_DEFAULT_PATH "/sys_prod/etc/nearlink_sle_config/"
#endif

#ifndef SLE_FILE_PATH
#define SLE_FILE_PATH "/data/nearlink_sle/"
#endif

#ifndef SLE_LOG_FILE_PATH
#define SLE_LOG_FILE_PATH SLE_FILE_PATH"device_log/"
#define SLE_SDK_LOG SLE_LOG_FILE_PATH"sle_sdk.log"
#define SLE_SDK_BAK_LOG SLE_LOG_FILE_PATH"sle_sdk.log.bak"
#endif

typedef std::map<std::string, std::string> SleConfigValue;
typedef std::map<std::string, SleConfigValue> SleConfigValueMap;

class SleConfigManager {
public:
    SleConfigManager(std::string fileName);
    ~SleConfigManager();
    SleErrorCode UpdateValueToFile(void);
    SleErrorCode UpdateValueFromFile(void);
    SleErrorCode GetValue(SleConfigValueMap &values);
    SleErrorCode SetValue(const SleConfigValueMap &values);
    uint8_t Str2Uint8(const std::string &str);
    uint16_t Str2Uint16(const std::string &str);
    uint32_t Str2Uint32(const std::string &str);
    bool str2Bool(const std::string &str);
    void PrintSleConfigValueMap(const SleConfigValueMap values);
private:
    SleErrorCode ResetDefaultConfigFile(void);
    void TrimString(std::string &str);
    std::string fileName_;
    SleConfigValueMap valueMap_;
};

} // SleStandard
} // NearLink
} // OHOS

#endif //SLE_CONCIFG_MANAGER_H